package com.bvgol.examples.my.json;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.support.spring.PropertyPreFilters;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @program: my-spring-completely
 * @description:
 * @author: GUOCHEN
 * @create: 2021/04/08 17:39
 */
public class Test {
    public static void main(String[] args) {
        String jsonArray = "[{\"tradeAmount\":\"0.08\",\"port\":2},{\"tradeAmount\":\"0.01\",\"port\":1},{\"tradeAmount\":\"0.01\",\"port\":13},{\"tradeAmount\":\"0.10\",\"port\":9},{\"tradeAmount\":\"0.01\",\"port\":8},{\"tradeAmount\":\"0.00\",\"port\":19}]";
        JSONArray objects = JSON.parseArray(jsonArray);
//        System.out.println(objects);
//        System.out.println(objects.size());
//
        for (int i = 0; i < objects.size(); i++) {
            JSONObject jsonObject = objects.getJSONObject(i);
            Integer port = jsonObject.getInteger("port1");
//            System.out.println(port);
//            if (port.equals(1) || port.equals(2)) {
//                objects.remove(jsonObject);
//            }
        }
//        System.out.println(objects);

        boolean aTrue = Boolean.getBoolean("true");
        System.out.println("aTrue = " + aTrue);
        Boolean aBoolean = Boolean.valueOf("true");
        System.out.println("aBoolean = " + aBoolean);

        JsonExclude jsonExclude = new JsonExclude();
        jsonExclude.setPassword("pasaword");
        jsonExclude.setPassword2("pasaword2");

        String s = JSONObject.toJSONString(jsonExclude, excludePropertyPreFilter());
        System.out.println("s = " + s);

    }
    /**
     * 排除敏感属性字段
     */
    public static final String[] EXCLUDE_PROPERTIES = {"password", "oldPassword", "newPassword", "confirmPassword"};


    /**
     * 忽略敏感属性
     */
    public static PropertyPreFilters.MySimplePropertyPreFilter excludePropertyPreFilter() {
        return new PropertyPreFilters().addFilter().addExcludes(EXCLUDE_PROPERTIES);
    }
}

@Data
@AllArgsConstructor
@NoArgsConstructor
class JsonExclude{

    private String password;
    private String password2;

}
